package list;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Package: list
 * @ClassName: TestList
 * @Author: lujieni
 * @Description: 测试for循环的语法
 * @Date: 2020-12-11 13:10
 * @Version: 1.0
 */
public class TestFor {

    @Test
    public void test1(){

        Holder holder = new Holder();
        holder.hello();


        int i = 2;
        for(;i<3;i++){
            System.out.println(i);
        }
        System.out.println(i);
    }

    @Test
    public void test2(){
        String content = new String("");
        if(content != null && content != ""){
            System.out.println("aa");
        }else{
            System.out.println("bb");
        }
    }

    @Test
    public void test3(){
        String [] strings = {"aa", "bb", "cc"};
        List<String> list = Arrays.asList(strings);
        strings[0] = "sad";
        for (String s: list) {
            System.out.println(s);
        }
    }

    @Test
    public void test4(){
        System.out.println(Arrays.asList("FDC", "ESC").contains("fdc"));
    }

    /**
     * 增强for循环里不能删除元素,不然会有异常
     * 原因: remove 方法会修改modCount,for循环依赖Itr
     * Itr中会校验是否 modCount = expectedModCount
     * 不等于就报错
     */
    @Test
    public void test5(){
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        for (String s : list) {
            System.out.println("aa");
            list.remove(s);
        }
        System.out.println(list.size());
    }
}